package com.cloud.edu.shiro.filter;

import java.io.IOException;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;


/**
 * shiro session失效处理
 * @author dehuisun
 *
 */
public class CustomFormAuthenticationFilter extends FormAuthenticationFilter{
	
	@Override  
    protected boolean onAccessDenied(ServletRequest arg0, ServletResponse arg1) throws Exception {  
//		 HttpServletRequest request =(HttpServletRequest) arg0;
		 HttpServletResponse response =(HttpServletResponse) arg1;
		 String requestURI = getPathWithinApplication(arg0);
		 System.out.print("requestURI"+requestURI);
		 
		 try {
	    	   JSONObject returnObj = new JSONObject();
	    	   returnObj.element("httpCode", "SHIRO_EXPIRE");//shiro session 获取
	   		   response.setContentType("text/json; charset=utf-8");
			   response.setCharacterEncoding("UTF-8");
			   response.getWriter().print(returnObj.toString());
			   response.getWriter().close();
	       } catch (IOException e) {
	           e.printStackTrace();
	       }
		 return false;
//		 return super.onAccessDenied(request, response);  
      
    }  
}
